//======================================================================
//
//	Cross-Platform XNA Menu System
//  http://cpxms.codeplex.com/
//
//  All code and content licensed under Microsoft Public License (Ms-PL)	
//
//======================================================================
//
//	File:		SpacePongGame.cs
//
//	Author:		MJP
//
//	Date:		05/17/09
//
//======================================================================

using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using CPXMenu;

namespace CPXMenuSample
{
   
	/// <summary>
	/// The Game class for the sample
	/// </summary>
    public class SpacePongGame : Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        MainMenuComponent mainMenuComponent;

        PlayerIndex gamepadIndex = PlayerIndex.One;

		/// <summary>
		/// Gets the PlayerIndex on which the gamepad was detected
		/// </summary>
        public PlayerIndex GamepadIndex
        {
            get { return gamepadIndex; }
        }

		/// <summary>
		/// Creates a new SpacePongGame instance
		/// </summary>
        public SpacePongGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// Sets graphics settings, attempts to detect a gamepad, and creates the MainMenuComponent
        /// </summary>
        protected override void Initialize()
        {
            this.graphics.PreferredBackBufferWidth = 1280;
            this.graphics.PreferredBackBufferHeight = 720;            
            this.graphics.ApplyChanges();

			// Look for a gamepad on all 4 ports
            for (int i = 0; i < 4; i++)
            {
                if (GamePad.GetState((PlayerIndex)i).IsConnected)
                {
                    gamepadIndex = (PlayerIndex)i;
                    break;
                }
            }

			// Make our MainMenuComponent and add it to the Components collection
            mainMenuComponent = new MainMenuComponent(this);
            this.Components.Add(mainMenuComponent);

            base.Initialize();
        }

        /// <summary>
        /// Loads content required by the sample
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
        }

        /// <summary>
        /// Unloads content for the sample
        /// </summary>
        protected override void UnloadContent()
        {
            
        }

        /// <summary>
        /// Polls for user input, and updates the simulation
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(gamepadIndex).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            base.Update(gameTime);
        }

        /// <summary>
        /// Draws the sample
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);            

            base.Draw(gameTime);
        }
    }
}
